package com.xht.controller;

import com.xht.domain.ResponseResult;
import com.xht.domain.dto.LinkChangeStatusDto;
import com.xht.domain.entity.Link;
import com.xht.service.impl.LinkServiceImpl;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/link")
public class LinkController {

    private final LinkServiceImpl linkService;

    public LinkController(LinkServiceImpl linkService) {
        this.linkService = linkService;
    }

    /**
     * 显示 友联列表
     * 模糊查询 和 状态查询
     */
    @GetMapping("/list")
    public ResponseResult linkList(Integer pageNum, Integer pageSize, String name, String status) {
        return linkService.linkList(pageNum, pageSize, name, status);
    }

    /**
     * 新增友联
     */
    @PostMapping
    public ResponseResult addLink(@RequestBody Link link) {
        return linkService.addLink(link);
    }

    /**
     * 根据id回显友联信息
     */
    @GetMapping("/{id}")
    public ResponseResult getLinkById(@PathVariable Integer id) {
        return linkService.getLinkById(id);
    }

    /**
     * 更新 友联信息
     */
    @PutMapping
    public ResponseResult updateLink(@RequestBody Link link) {
        return linkService.updateLink(link);
    }

    /**
     * 逻辑删除友联
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteLink(@PathVariable Integer id) {
        return linkService.deleteLink(id);
    }

    /**
     * 更新友联状态
     */
    @PutMapping("/changeLinkStatus")
    public ResponseResult changeLinkStatus(@RequestBody LinkChangeStatusDto linkChangeStatusDto) {
        return linkService.changeLinkStatus(linkChangeStatusDto);
    }

}
